Preserve FCM token after service worker reset (version tap)#187
Merged
Preserve FCM token after service worker reset (version tap)#187
Conversation
Co-authored-by: ProLoser <67395+ProLoser@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix version update logic to preserve notification token
Preserve FCM token after service worker reset (version tap)
Mar 20, 2026
|
There was a problem hiding this comment.
Pull request overview
Adjusts FCM token persistence logic so users who already granted notifications don’t silently lose notifications after a service worker reset (e.g., via “version tap” unregistering SW and rotating the FCM token).
Changes:
- Broaden token auto-save condition to run when notification permission is not
'denied'(including'granted'), so rotated tokens get re-written to Firebase.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+108
to
110
| // Also re-save on 'granted' in case the service worker was refreshed (e.g. version reset) | ||
| if (window.Notification?.permission !== 'denied') | ||
| tokensRef.once('value', snapshot => snapshot.child(token).exists() || saveFcmToken()) |
There was a problem hiding this comment.
getFcmToken() can resolve with a falsy token (e.g. null) when Messaging can't provide one yet. In that case snapshot.child(token) will throw and break this effect. Guard against a missing token before calling .child(...) (and decide whether you want to call saveFcmToken() when token is missing).
ProLoser
approved these changes
Mar 21, 2026
Owner
|
@copilot address feedback |
Co-authored-by: ProLoser <67395+ProLoser@users.noreply.github.com> Agent-Logs-Url: https://github.com/ProLoser/PeaceInTheMiddleEast/sessions/e9dcb60a-6d60-48c7-be8d-97a0aa428e7a
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Friends.tsxto auto-save FCM token when permission is already'granted'but the current token is missing from Firebase (covers the case after a version reset clears the service worker)tokenfromgetFcmToken()before callingsnapshot.child(token)Original prompt
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.